package com.taomu.app.zongchouhuli.moudle.mine.activity;

import android.content.Context;
import android.content.Intent;
import android.media.Image;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.taomu.app.zongchouhuli.R;
import com.taomu.app.zongchouhuli.entity.BaseChangeResponse;
import com.taomu.app.zongchouhuli.framework.BaseActivity;
import com.taomu.app.zongchouhuli.http.res.ResProductIncomeDetailEntity;
import com.taomu.app.zongchouhuli.moudle.mine.adpter.IncomeDetailAdp;
import com.taomu.app.zongchouhuli.moudle.mine.contract.UserIncomeDetailContract;
import com.taomu.app.zongchouhuli.moudle.mine.contract.impl.UserIncomeDetailPresenter;
import com.taomu.app.zongchouhuli.moudle.mine.entity.IncomeDetailEnttiy;
import com.taomu.app.zongchouhuli.utils.TimeUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 收益详情
 */
public class UserIncomeDetailActivity extends BaseActivity<UserIncomeDetailContract.Presenter> implements UserIncomeDetailContract.View {

    private ImageView mBackIm;

    private ImageView mProductIconIm;

    private TextView mProductNameTv;

    private TextView mProductPriceTv;

    //收益
    private TextView mIncomeTv;

    private RecyclerView mIncomeDetailRecy;

    private IncomeDetailAdp mAdp;

    public static final String PRODUCTID = "productid";

    public static void start(Context mContext,String id){
        Intent intent = new Intent(mContext,UserIncomeDetailActivity.class);
        intent.putExtra(PRODUCTID, id);
        mContext.startActivity(intent);
    }

    @Override
    protected void onDestroy() {
        mPresenter.onDetch();
        super.onDestroy();
    }

    @Override
    protected int getContentLayout() {
        return R.layout.activity_income_detail;
    }

    @Override
    protected void initView() {
        mBackIm = findViewById(R.id.income_detail_back_im);
        mProductIconIm = findViewById(R.id.income_detail_product_im);
        mProductNameTv = findViewById(R.id.income_detail_title_tv);
        mProductPriceTv = findViewById(R.id.income_detail_price_tv);
        mIncomeTv = findViewById(R.id.income_detail_income_tv);
        mAdp = new IncomeDetailAdp(this);
        mIncomeDetailRecy = findViewById(R.id.income_detail_recy);
        mIncomeDetailRecy.setLayoutManager(new LinearLayoutManager(this));
        mIncomeDetailRecy.setAdapter(mAdp);
    }

    private String id = "-1";

    @Override
    protected void initData() {
        if(getIntent() != null){
            id = getIntent().getStringExtra(PRODUCTID);
        }
        mPresenter.getProductInfo(id);
        mPresenter.getIncomeDetailList();
    }

    @Override
    protected void initEvent() {
        mBackIm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    @Override
    protected UserIncomeDetailContract.Presenter createPresenter() {
        return new UserIncomeDetailPresenter(this);
    }

    @Override
    public void setProductInfo(BaseChangeResponse<ResProductIncomeDetailEntity> baseResponse) {
        Glide.with(this).load(baseResponse.getData().getProduct_img_uri()).into(mProductIconIm);
        mProductNameTv.setText(baseResponse.getData().getProduct_name());
        mProductPriceTv.setText("¥"+baseResponse.getData().getProduct_price());
//        if("day_income".equals(baseResponse.getData().getIncome_type())){
//            mIncomeTv.setText("最高收益"+baseResponse.getData().getDay_income()+"%");
//        }else if("week_income".equals(baseResponse.getData().getIncome_type())){
//            mIncomeTv.setText("最高收益"+baseResponse.getData().getWeek_income()+"%");
//        }else if("month_income".equals(baseResponse.getData().getIncome_type())){
            mIncomeTv.setText("最高收益"+baseResponse.getData().getMonth_income()+"%");
//        }
        List<IncomeDetailEnttiy> mData = new ArrayList<>();
        IncomeDetailEnttiy enttiy1 = new IncomeDetailEnttiy();
        enttiy1.setKey("产品名称:");
        enttiy1.setValue(baseResponse.getData().getProduct_name());
        mData.add(enttiy1);
        IncomeDetailEnttiy enttiy2 = new IncomeDetailEnttiy();
        enttiy2.setKey("产品金额:");
        enttiy2.setValue(baseResponse.getData().getProduct_price()+"元");
        mData.add(enttiy2);
        IncomeDetailEnttiy enttiy3 = new IncomeDetailEnttiy();
        enttiy3.setKey("本月收益:");
        //todo:本月收益是哪一个
        enttiy3.setValue(String.valueOf(baseResponse.getData().getMonthBenefit())+"元");
        mData.add(enttiy3);
        IncomeDetailEnttiy enttiy4 = new IncomeDetailEnttiy();
        enttiy4.setKey("获益形式:");
        //todo:缺少获益形式
        enttiy4.setValue(baseResponse.getData().getAccount_type_name());
        mData.add(enttiy4);
        IncomeDetailEnttiy enttiy5 = new IncomeDetailEnttiy();
        enttiy5.setKey("购买时间:");
        if(!TextUtils.isEmpty(baseResponse.getData().getCreate_date())) {
            enttiy5.setValue(TimeUtils.timeFomart(Long.valueOf(baseResponse.getData().getCreate_date())));
        }
        mData.add(enttiy5);
        mAdp.setData(mData);
    }

    @Override
    public void setIncomeDetailList(List<IncomeDetailEnttiy> mData) {
        //mAdp.setData(mData);
    }

    @Override
    public void setPresenter(UserIncomeDetailContract.Presenter presenter) {

    }
}
